<template>
	<wd-card v-if="props.address" class="address">
		<wd-cell-group>
			<wd-cell title="姓名" :value="props.address.realName" />
			<wd-cell title="手机" :value="props.address.userPhone" />
			<wd-cell title="地址" :label="props.address.detailedAddress" />
			<!-- <wd-cell>
				<template #title>
					<text>是否默认</text>
				</template>
				<wd-switch
					prop="isDefault"
					@change="handleChange(props.address)"
					v-model="props.address.isDefault"
				></wd-switch>
			</wd-cell> -->
		</wd-cell-group>
		<template #footer>
			<wd-button size="small" plain @click="handleOpen">编辑</wd-button>
		</template>
	</wd-card>
</template>
<script setup>
import { http } from '@/utils/http'

const props = defineProps({
	address: {
		type: Object,
		default: null,
	},
})

const emits = defineEmits(['update'])

const handleChange = async (address) => {
	let res = await http({ url: '/address/setUserDefault', method: 'post', data: { id: address.id } })
	if (res.code == 200) {
		console.log('res', res)
		emits('update')
	}
}
const handleOpen = () => {
	uni.navigateTo({ url: '/pages/address/edit?id=' + props.address.id })
}
</script>
<style scoped lang="scss">
.address {
	box-sizing: border-box;
	width: 710rpx;
	margin: 24rpx 0;
}
</style>
